package com.bw.source;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName: SourceCollection
 * @Author: huzx
 * @Date: 2025-01-03 09:58
 * @Version: 1.0
 **/
public class SourceCollection {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
//        DataStreamSource<Integer> source = env.fromElements(1, 2, 3, 4, 5);
//        source.print();

//        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
//        DataStreamSource<Integer> source = env.fromCollection(list);
//        source.print();

//        https://nightlies.apache.org/flink/flink-docs-release-1.17/docs/connectors/datastream/formats/text_files/
        FileSource<String> fileSource
                = FileSource.forRecordStreamFormat(new TextLineInputFormat(), new Path("input/words.txt")).build();
        env.fromSource(fileSource,
                WatermarkStrategy.noWatermarks(),
                "file")
                .print();

        env.execute();
    }
}
